package org.learn.simple.file.server.handlers;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author <a href="mailto:675464934@qq.com">Terrdi</a>
 * @date 2021/12/19
 * @since 1.8
 **/
public class FileServerInitializer extends ChannelInitializer<SocketChannel> {
    private final String basePath;

    public FileServerInitializer(String basePath) {
        this.basePath = basePath;
    }


    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast(new HttpServerCodec())
                .addLast(new ShowDirectoryHandler())
                .addLast(new SearchFileHandler(this.basePath));
    }
}
